<!DOCTYPE html><html><head><title>文件管理器书签视图插件</title><meta charset='utf-8'><link href='https://dn-maxiang.qbox.me/res-min/themes/marxico.css' rel='stylesheet'><style></style></head><body><div id='preview-contents' class='note-content'>
                        
                    



<h1 id="文件管理器书签视图插件">文件管理器书签视图插件</h1>

<h4 id="１继承viewinterface遵守qt的插件规范实现你的书签视图插件接口">１．继承ViewInterface，遵守Qt的插件规范实现你的书签视图插件接口</h4>

<ul><li><h6 id="插件头文件">插件头文件</h6>

<p>如果你安装了<code>libdde-file-manager-dev</code>你可以在如下路径找到<strong>viewinterface.h</strong></p>

<ul>
<li><p>在/etc/apt/source.list中添加如下源：</p>

<pre class="prettyprint hljs-dark"><code class="hljs groovy">deb-src <span class="hljs-string">http:</span><span class="hljs-comment">//pools.corp.deepin.com/deepin unstable main non-free</span><br></code></pre></li>
<li><p>升级安装libdde-file-manager-dev</p>

<pre class="prettyprint hljs-dark"><code class="hljs q">sudo apt-<span class="hljs-built_in">get</span> <span class="hljs-keyword">update</span><br>sudo apt-<span class="hljs-built_in">get</span> install libdde-file-manager-<span class="hljs-built_in">dev</span><br></code></pre></li>
<li>就可以找到<code>/usr/include/dde-file-manager/viewinterface.h</code></li></ul>

<p>同样可以在 git clone <a href="https://github.com/linuxdeepin/dde-file-manager" target="_blank">https://github.com/linuxdeepin/dde-file-manager</a>　下载源码到<code>dde-file-manager</code>, 切到<code>develop2.0分支</code> 可以找到<code>dde-file-manager/dde-file-manager-plugins/plugininterfaces/view/viewinterface.h</code></p></li>
<li><h6 id="接口说明">接口说明：</h6>

<ul>
<li><code>virtual QString bookMarkText()</code>;  侧边栏书签对应文本</li>
<li><code>virtual QIcon bookMarkNormalIcon()</code>;　侧边栏书签normal状态图标</li>
<li><code>virtual QIcon bookMarkHoverIcon()</code>;　侧边栏书签hover状态图标</li>
<li><code>virtual QIcon bookMarkPressedIcon()</code>;　侧边栏书签pressed状态图标 <br>
+<code>virtual QIcon bookMarkCheckedIcon()</code>;　侧边栏书签checked状态图标</li>
<li><code>virtual QString crumbText()</code>;　顶部面包屑文本</li>
<li><code>virtual QIcon crumbNormalIcon()</code>;　顶部面包屑normal状态图标</li>
<li><code>virtual QIcon crumbHoverIcon()</code>; 顶部面包屑hover状态图标</li>
<li><code>virtual QIcon crumbPressedIcon()</code>; 顶部面包屑pressed状态图标</li>
<li><code>virtual QIcon crumbCheckedIcon()</code>; 顶部面包屑checked状态图标</li>
<li><code>virtual bool isAddSeparator()</code>; 侧边栏书签是否添加分隔符</li>
<li><code>virtual QString scheme()</code>; 视图遵循的协议例如computer:// 、trash://、usershare:// 中的computer、trash、usershare等字符串</li>
<li><code>virtual QWidget* createView()</code>;　返回视图协议对应的QWidget对象指针</li></ul></li>
<li><h5 id="插件默认安装目录">插件默认安装目录</h5>

<ul>
<li>x86架 <br>
<ul>
<li><code>/usr/lib/x86_64-linux-gnu/dde-file-manager/plugins/view/</code> 64位</li>
<li><code>/usr/lib/x86_32-linux-gnu/dde-file-manager/plugins/view/</code>32位   </li></ul></li>
<li>龙芯架构 <br>
<ul>
<li><code>/usr/lib/mipsel-linux-gnu//dde-file-manager/plugins/view/</code> </li></ul></li>
<li>神威架构 <br>
<ul>
<li><code>/usr/lib/sw_64-linux-gnu/dde-file-manager/plugins/view/</code></li></ul></li></ul></li>
<li><h6 id="源码">源码：</h6>

<pre class="prettyprint hljs-dark"><code class="hljs gherkin"><span class="hljs-comment">#ifndef VIEWINTERFACE_H</span><br><span class="hljs-comment">#define VIEWINTERFACE_H</span><br><br><span class="hljs-comment">#include &lt;QString&gt;</span><br><span class="hljs-comment">#include &lt;QIcon&gt;</span><br><span class="hljs-comment">#include &lt;QWidget&gt;</span><br>/<span class="hljs-keyword">*</span><br> <span class="hljs-keyword">*</span> The view interface of dde-file-manager<br> <span class="hljs-keyword">*</span> 文件管理器的视图插件接口<br><span class="hljs-keyword">*</span>/<br>class ViewInterface<br>{<br>public:<br>    virtual ~ViewInterface() {}<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkText<br>     <span class="hljs-keyword">*</span> \return QString: the text of leftbar bookmark which should be 16X16 size<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkText<br>     <span class="hljs-keyword">*</span> \return QString:　侧边栏书签文本内容<br>     <span class="hljs-keyword">*</span>/\<br>    virtual QString bookMarkText(){<br>        return <span class="hljs-string">""</span>;<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkNormalIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the release icon of leftbar bookmark which should be 16X16 size<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkNormalIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: release状态-侧边栏书签Icon<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon bookMarkNormalIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkHoverIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the hover icon of leftbar bookmark which should be 16X16 size<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkHoverIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: hover状态-侧边栏书签Icon<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon bookMarkHoverIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkPressedIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the pressed hover icon of leftbar bookmark which should be 16X16 size<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkPressedIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: pressed状态-侧边栏书签Icon<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon bookMarkPressedIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkCheckedIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the checked icon of leftbar bookmark which should be 16X16 size<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief bookMarkCheckedIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: checked状态-侧边栏书签Icon<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon bookMarkCheckedIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbText<br>     <span class="hljs-keyword">*</span> \return QString: text of first crumbButton in titlebar<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbText<br>     <span class="hljs-keyword">*</span> \return QString: 第一个面包屑的显示文本<br>     <span class="hljs-keyword">*</span>/<br>    virtual QString crumbText(){<br>        return <span class="hljs-string">""</span>;<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbNormalIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the normal icon of first crumbButton in titlebar<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbNormalIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: 第一个面包屑的normal状态图标<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon crumbNormalIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbHoverIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the hover icon of first crumbButton in titlebar<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbHoverIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: 第一个面包屑的normal状态图标<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon crumbHoverIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbPressedIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the pressed icon of first crumbButton in titlebar<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbHoverIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: 第一个面包屑的pressed状态图标<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon crumbPressedIcon(){<br>        return QIcon();<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbCheckedIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: the checked icon of first crumbButton in titlebar<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief crumbHoverIcon<br>     <span class="hljs-keyword">*</span> \return QIcon: 第一个面包屑的checked状态图标<br>     <span class="hljs-keyword">*</span>/<br>    virtual QIcon crumbCheckedIcon(){<br>        return QIcon();<br>    }<br><br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief isAddSeparator<br>     <span class="hljs-keyword">*</span> \return bool: addSeparator whether or not<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief isAddSeparator<br>     <span class="hljs-keyword">*</span> \return bool:是否添加书签分隔符<br>     <span class="hljs-keyword">*</span>/<br>    virtual bool isAddSeparator(){<br>        return false;<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief scheme<br>     <span class="hljs-keyword">*</span> \return QString: scheme of view which should by like computer 、trash、 usershare　and so on<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief scheme<br>     <span class="hljs-keyword">*</span> \return QString: 视图view对应的协议头，譬如computer 、trash、 usershare等<br>     <span class="hljs-keyword">*</span>/<br>    virtual QString scheme(){<br>        return <span class="hljs-string">""</span>;<br>    }<br><br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief createView<br>     <span class="hljs-keyword">*</span> \return QWidget<span class="hljs-keyword">*</span> : the view will be registered into dde-file-manager view<br>     <span class="hljs-keyword">*</span>/<br>    /<span class="hljs-keyword">*</span>!<br>     <span class="hljs-keyword">*</span> \brief createView<br>     <span class="hljs-keyword">*</span> \return QWidget<span class="hljs-keyword">*</span>: 注册到文件管理器视图区域的视图控件<br>     <span class="hljs-keyword">*</span>/<br>    virtual QWidget<span class="hljs-keyword">*</span> createView(){<br>        return NULL;<br>    }<br>};<br><br><span class="hljs-comment">#define ViewInterface_iid "com.deepin.dde-file-manager.ViewInterface"</span><br>Q_DECLARE_INTERFACE(ViewInterface,ViewInterface_iid)<br><br><span class="hljs-comment">#endif // VIEWINTERFACE_H</span><br></code></pre></li>
<li><p>示例</p>

<pre class="prettyprint hljs-dark"><code class="hljs scss"><span class="hljs-id">#include</span> "viewplugin<span class="hljs-class">.h</span>"<br><span class="hljs-id">#include</span> &lt;QLabel&gt;<br><br>ViewPlugin<span class="hljs-value">::<span class="hljs-function">ViewPlugin</span>(QObject *parent) :<br>    <span class="hljs-function">QObject</span>(parent)<br>{<br>    <span class="hljs-function">Q_INIT_RESOURCE</span>(pluginview);</span><br>}<br><br>QString ViewPlugin<span class="hljs-value">::<span class="hljs-function">bookMarkText</span>()<br>{<br>    return <span class="hljs-string">"view"</span>;</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">bookMarkNormalIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/release.png"</span>);</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">bookMarkHoverIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/hover.png"</span>);</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">bookMarkPressedIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/pressed.svg"</span>);</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">bookMarkCheckedIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/checked.svg"</span>);</span><br>}<br><br>QString ViewPlugin<span class="hljs-value">::<span class="hljs-function">crumbText</span>()<br>{<br>    return <span class="hljs-string">"view"</span>;</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">crumbNormalIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/release.png"</span>);</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">crumbHoverIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/hover.png"</span>);</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">crumbPressedIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/hover.png"</span>);</span><br>}<br><br>QIcon ViewPlugin<span class="hljs-value">::<span class="hljs-function">crumbCheckedIcon</span>()<br>{<br>    return <span class="hljs-function">QIcon</span>(<span class="hljs-string">":/images/checked.svg"</span>);</span><br>}<br><br>bool ViewPlugin<span class="hljs-value">::<span class="hljs-function">isAddSeparator</span>()<br>{<br>    return true;</span><br>}<br><br>QString ViewPlugin<span class="hljs-value">::<span class="hljs-function">scheme</span>()<br>{<br>    return <span class="hljs-string">"view"</span>;</span><br>}<br><br>QWidget *ViewPlugin<span class="hljs-value">::<span class="hljs-function">createView</span>()<br>{<br>    QLabel* label = new QLabel;</span><br>    <span class="hljs-tag">label</span>-&gt;<span class="hljs-function">setText</span>("view");<br>    <span class="hljs-tag">label</span>-&gt;<span class="hljs-function">setAlignment</span>(Qt<span class="hljs-value">::AlignCenter);</span><br><span class="hljs-comment">//    label-&gt;setStyleSheet("background-color: green; margins:0");</span><br>    return <span class="hljs-tag">label</span>;<br>}<br></code></pre></li>
<li><p>预览效果 <br>
　 <img longdesc="./深度截图20161223111044.png" alt="view" title="" type="image/png" src="" class=""></p></li>
</ul></div></body></html>